﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using GGJ_DKG.Objects;
using GGJ_DKG.Menu;
using GGJ_DKG.Managers;
namespace GGJ_DKG.Managers
{
    static class Input
    {

        static public KeyboardState ks;
        static public KeyboardState old_ks;
        static public GamePadState gp;
        static public GamePadState old_gp;
        static public MouseState ms;
        static public MouseState old_ms;
        public static int buttonPresses;
        static bool nextKeyUp = true;
        static bool nextKeyDown = true;
        static bool nextKeyRight = true;
        static bool nextKeyLeft = true;
        static bool nextKeyA = true;
        static bool nextKeyD = true;
        
        public enum key
        {
             A, D, Down, Up, Rigth, Left
        }

       
        static public bool GetKey(key currentKey)
        {
            switch (currentKey)
            {
                case key.Down:
                    if (old_ks != ks)
                    {
                        if (ks.IsKeyDown(Keys.Down) && nextKeyDown)
                        {
                            nextKeyA = true;
                            nextKeyUp = true;
                            nextKeyDown = false;
                            nextKeyRight = true;
                            nextKeyLeft = true;
                            nextKeyD = true;
                            buttonPresses++;
                            return true;
                        }
                    }
                    break;
                case key.A:
                    if (old_ks != ks)
                    {
                        if (ks.IsKeyDown(Keys.A) && nextKeyA)
                        {
                            nextKeyA = false;
                            nextKeyUp = true;
                            nextKeyDown = true;
                            nextKeyRight = true;
                            nextKeyLeft = true;
                            nextKeyD = true;
                            buttonPresses++;
                            return true;
                        }
                    }
                    break;
                case key.Rigth:
                    if (old_ks != ks)
                    {
                        if (ks.IsKeyDown(Keys.Right) && nextKeyRight)
                        {
                            nextKeyUp = true;
                            nextKeyDown = true;
                            nextKeyA = true;
                            nextKeyRight = false;
                            nextKeyLeft = true;
                            nextKeyD = true;
                            buttonPresses++;
                            return true;
                        }
                    }
                    break;

                case key.Left:
                    if (old_ks != ks)
                    {
                        if (ks.IsKeyDown(Keys.Left) && nextKeyLeft)
                        {
                            nextKeyUp = true;
                            nextKeyDown = true;
                            nextKeyA = true;
                            nextKeyRight = true;
                            nextKeyLeft = false;
                            nextKeyD = true;
                            buttonPresses++;
                            return true;
                        }
                    }
                    break;

                case key.D:
                    if (old_ks != ks)
                    {
                        if (ks.IsKeyDown(Keys.D) && nextKeyD)
                        {
                            nextKeyUp = true;
                            nextKeyDown = true;
                            nextKeyA = true;
                            nextKeyRight = true;
                            nextKeyLeft = true;
                            nextKeyD = false;
                            buttonPresses++;
                            return true;
                        }
                    }
                    break;
            }

            return false;
        }

        static public bool GetDown(Keys currentKey)
        {
            if (old_ks != ks)
            {
                if(ks.IsKeyDown(currentKey)) {
                    buttonPresses++; 
                    return true;
                }
                else{return false;}
            }else{return false;}

        }
    }
}